//---------------------------------------------------------------------
// File: Operations.cs
// 
// Summary: This class is invokes the ESB.BizTalkOperations Assembly. It is 
//          the wrapper that exposes the BizTalk Server Environment.
//          This is an Infrastructure Service.
//---------------------------------------------------------------------
// This file is part of the Microsoft ESB Guidance for BizTalk
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft BizTalk
// Server 2006 R2 release and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Threading;
using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.Practices.ESB.BizTalkOperations;
using Resources;
using Microsoft.Practices.ESB.Exception.Management;

[WebService(Namespace = "http://Microsoft.Practices.ESB.BizTalkOperationsService/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Operations : WebService
{
    private BizTalkQuery bizTalkQuery;

    #region Error code constants

    private const int BizTalkQueryServiceApplicationsMessage = 251001;
    private const int BizTalkQueryServiceApplicationStatusMessage = 251002;
    private const int BizTalkQueryServiceCreateApplicationMessage = 251003;
    private const int BizTalkQueryServiceCreateReceiveLocationMessage = 251004;
    private const int BizTalkQueryServiceCreateReceivePortMessage = 251005;
    private const int BizTalkQueryServiceCreateSendPortMessage = 251006;
    private const int BizTalkQueryServiceDeleteApplicationMessage = 25107;
    private const int BizTalkQueryServiceDeleteReceiveLocationMessage = 251008;
    private const int BizTalkQueryServiceDeleteReceivePortMessage = 251009;
    private const int BizTalkQueryServiceDeleteSendPortMessage = 251010;
    private const int BizTalkQueryServiceHostsMessage = 251011;
    private const int BizTalkQueryServiceMessage = 251012;
    private const int BizTalkQueryServiceOrchestrationInstanceMessage = 251013;
    private const int BizTalkQueryServiceOrchestrationsMessage = 251014;
    private const int BizTalkQueryServicePipelinesMessage = 251015;
    private const int BizTalkQueryServiceReceiveLocationsMessage = 251016;
    private const int BizTalkQueryServiceReceivePortsMessage = 251017;
    private const int BizTalkQueryServiceSchemasMessage = 251018;
    private const int BizTalkQueryServiceSendPortsMessage = 251019;
    private const int BizTalkQueryServiceStatusChangedMessage = 251020;
    private const int BizTalkQueryServiceSystemStatusMessage = 251021;
    private const int BizTalkQueryServiceUpdateApplicationMessage = 251022;
    private const int BizTalkQueryServiceUpdateReceiveLocationMessage = 251023;
    private const int BizTalkQueryServiceUpdateReceivePortMessage = 251024;
    private const int BizTalkQueryServiceUpdateSendPortMessage = 251025;
    private const int BizTalkQueryServiceTransformsMessage = 251026;

    #endregion

    #region Constructor

    /// <summary>
    /// Default constructor. Initializes the BizTalkQuery class
    /// </summary>
    public Operations()
    {
        try
        {
            bizTalkQuery = new BizTalkQuery();
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceMessage), SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Error Utilities

    /// <summary>
    /// looks up exceptions descriptions based on error codes. prepends "e"
    /// for lookup in resource file
    /// </summary>
    /// <param name="errorCode">code represented by constant</param>
    /// <returns>string representing error code</returns>
    private static string GetErrorDescription(int errorCode)
    {
        try
        {
            // Get the culture of the currently executing thread.
            // The value of ci will determine the culture of
            // the resources that the resource manager retrieves.
            CultureInfo ci = Thread.CurrentThread.CurrentCulture;

            // Retrieve the value of the string resource and return it 
            string message =
                Exceptions.ResourceManager.GetString("e" + Convert.ToString(errorCode, NumberFormatInfo.CurrentInfo), ci);
            return message;
        }
        catch (Exception e)
        {
            throw e;
        }
    }

    /// <summary>
    /// looks up exceptions descriptions based on error codes. prepends "e"
    /// for lookup in resource file
    /// </summary>
    /// <param name="errorCode">code represented by constant</param>
    /// <param name="arguments">optional arguments to format in message</param>
    /// <returns>string representing error code</returns>
    private static string GetErrorDescription(int errorCode, params Object[] arguments)
    {
        try
        {
            // Get the culture of the currently executing thread.
            // The value of ci will determine the culture of
            // the resources that the resource manager retrieves.
            CultureInfo ci = Thread.CurrentThread.CurrentCulture;

            // Retrieve the value of the string resource and return it 
            string message =
                Exceptions.ResourceManager.GetString("e" + Convert.ToString(errorCode, NumberFormatInfo.CurrentInfo), ci);
            return string.Format(ci, message, arguments);
        }
        catch (Exception)
        {
            throw;
        }
    }

    #endregion

    #region Host operations

    /// <summary>
    /// Gets Host Instance information. Empty Host Name returns all BizTalk Server hosts.
    /// </summary>
    /// <param name="hostName">Biztalk Server Host Name: BizTalkServerApplication</param>
    /// <returns>List<BTQuery.BTHost></returns>
    [WebMethod]
    public List<BizTalkQuery.BTHost> Hosts(string hostName)
    {
        // the hostName parameter can be an empty string
        try
        {
            List<BizTalkQuery.BTHost> BTHosts = bizTalkQuery.Hosts(hostName);
            return BTHosts;
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceHostsMessage), SoapException.ServerFaultCode,
                                    ex);
        }
    }

    #endregion

    #region Application operations

    /// <summary>
    /// Returns information about specific BizTalk Server Application. 
    /// The input is the Application Name. 
    /// The Services returns information about Orchestrations, 
    /// Send Ports, Receive locations and Host Information to which the application belongs. 
    /// </summary>
    /// <param name="name">BizTalk Application Name</param>
    /// <returns>BTQuery.BTSysStatus</returns>
    [WebMethod]
    public BizTalkQuery.BTSysStatus ApplicationStatus(string name)
    {
        try
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            BizTalkQuery.BTSysStatus BTStatus = bizTalkQuery.ApplicationStatus(name);
            return BTStatus;
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceApplicationStatusMessage, name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all Application Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTApplication></returns>
    [WebMethod]
    public void CreateApplication(BizTalkQuery.BTApplication app)
    {
        try
        {
            bizTalkQuery.CreateApplication(app);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceCreateApplicationMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all Application Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTApplication></returns>
    [WebMethod]
    public void UpdateApplication(BizTalkQuery.BTApplication app)
    {
        try
        {
            bizTalkQuery.UpdateApplication(app);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceUpdateApplicationMessage, app.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all Application Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTApplication></returns>
    [WebMethod]
    public void DeleteApplication(BizTalkQuery.BTApplication app)
    {
        try
        {
            bizTalkQuery.DeleteApplication(app.Name);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceDeleteApplicationMessage, app.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all Application Names. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTApplication></returns>
    [WebMethod]
    public List<BizTalkQuery.BTApplication> ApplicationList()
    {
        try
        {
            return bizTalkQuery.ApplicationList();
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceApplicationsMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all Application Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTApplication></returns>
    [WebMethod]
    public List<BizTalkQuery.BTApplication> Applications()
    {
        try
        {
            return bizTalkQuery.Applications();
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceApplicationsMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Orchestration operations

    /// <summary>
    /// Gets all the Orchestration Information. 
    /// Empty Orchestration Name returns all Orchestrations.
    /// </summary>
    /// <param name="applicationName">Application Name</param>
    /// <param name="name">Orchestration Name</param>
    /// <returns>BTQuery.BTSysStatus </returns>
    [WebMethod]
    public List<BizTalkQuery.BTOrchestration> Orchestrations(string applicationName, string name)
    {
        // orchestration name can by empty
        try
        {
            return bizTalkQuery.Orchestrations(applicationName, name);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceOrchestrationsMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Gets all the Service Instances Information for a given Orchestration Name. 
    /// </summary>
    /// <param name="name">Orchestration Name</param>
    /// <returns>List<BTQuery.BTOrchInstance></returns>
    [WebMethod]
    public List<BizTalkQuery.BTOrchestrationInstance> GetOrchestrationInstances(string name)
    {
        try
        {
            return bizTalkQuery.GetOrchestrationInstances(name);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceOrchestrationInstanceMessage, name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Receive port operations

    /// <summary>
    /// Returns all Application Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTApplication></returns>
    [WebMethod]
    public void CreateReceivePort(BizTalkQuery.BTReceivePort port)
    {
        try
        {
            bizTalkQuery.CreateReceivePort(port);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceCreateReceivePortMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all ReceivePort Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTReceivePort></returns>
    [WebMethod]
    public void UpdateReceivePort(BizTalkQuery.BTReceivePort port)
    {
        try
        {
            bizTalkQuery.UpdateReceivePort(port);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceUpdateReceivePortMessage, port.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all ReceivePort Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTReceivePort></returns>
    [WebMethod]
    public void DeleteReceivePort(BizTalkQuery.BTReceivePort port)
    {
        try
        {
            bizTalkQuery.DeleteReceivePort(port);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceDeleteReceivePortMessage, port.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Gets all the Receive Ports Information. 
    /// Empty Application Name returns all Receive Ports in the Default Application.
    /// Empty Port Name returns all Receive Ports.
    /// </summary>
    /// <param name="applicationName">Application Name</param>
    /// <param name="name">Receive Port Name</param>
    /// <returns>BizTalkQuery.BTReceivePort</returns>
    [WebMethod]
    public List<BizTalkQuery.BTReceivePort> ReceivePorts(string applicationName, string name)
    {
        try
        {
            List<BizTalkQuery.BTReceivePort> retval = bizTalkQuery.ReceivePorts(applicationName, name);
            return retval;
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceReceivePortsMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Receive location operations

    /// <summary>
    /// Returns all Application Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTApplication></returns>
    [WebMethod]
    public void CreateReceiveLocation(BizTalkQuery.BTReceiveLocation location)
    {
        try
        {
            bizTalkQuery.CreateReceiveLocation(location);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceCreateReceiveLocationMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all ReceiveLocation Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTReceiveLocation></returns>
    [WebMethod]
    public void UpdateReceiveLocation(BizTalkQuery.BTReceiveLocation location)
    {
        try
        {
            bizTalkQuery.UpdateReceiveLocation(location);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceUpdateReceiveLocationMessage, location.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Returns all ReceiveLocation Names and Description. 
    /// The BTQuery invokes the BizTalk Explorer, iterates through 
    /// the applications and returns the application name and description.
    /// </summary>
    /// <returns>List<BTQuery.BTReceiveLocation></returns>
    [WebMethod]
    public void DeleteReceiveLocation(BizTalkQuery.BTReceiveLocation location)
    {
        try
        {
            bizTalkQuery.DeleteReceiveLocation(location);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceDeleteReceiveLocationMessage, location.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Gets all the Receive Locations Information. 
    /// Empty Application Name returns all Receive Ports in the Default Application.
    /// Empty Port Name returns all Receive Locations in the specified Receive Port.
    /// Empty Location Name returns all Receive Locations.
    /// </summary>
    /// <param name="applicationName">Application Name</param>
    /// <param name="portName">Port Name</param>
    /// <param name="name">Receieve Location Name</param>
    /// <returns>BizTalkQuery.BTReceiveLocation</returns>
    [WebMethod]
    public List<BizTalkQuery.BTReceiveLocation> ReceiveLocations(string applicationName, string portName, string name)
    {
        try
        {
            List<BizTalkQuery.BTReceiveLocation> locations =
                bizTalkQuery.ReceiveLocations(applicationName, portName, name);
            return locations;
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceReceiveLocationsMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Send port operations

    /// <summary>
    /// 
    /// </summary>
    /// <param name="port"></param>
    [WebMethod]
    public void CreateSendPort(BizTalkQuery.BTSendPort port)
    {
        try
        {
            bizTalkQuery.CreateSendPort(port);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceCreateSendPortMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="port"></param>
    [WebMethod]
    public void UpdateSendPort(BizTalkQuery.BTSendPort port)
    {
        try
        {
            bizTalkQuery.UpdateSendPort(port);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceUpdateSendPortMessage, port.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="port"></param>
    [WebMethod]
    public void DeleteSendPort(BizTalkQuery.BTSendPort port)
    {
        try
        {
            bizTalkQuery.DeleteSendPort(port);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceDeleteSendPortMessage, port.Name),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Gets all the Send Port Information. 
    /// Empty Application Name returns all Send Ports in the Default Application.
    /// Empty Port Name returns all Send Ports.
    /// </summary>
    /// <param name="applicationName">Application Name</param>
    /// <param name="name">Send Port Name</param>
    /// <returns>BizTalkQuery.BTSendPort</returns>
    [WebMethod]
    public List<BizTalkQuery.BTSendPort> SendPorts(string applicationName, string name)
    {
        try
        {
            List<BizTalkQuery.BTSendPort> retval = bizTalkQuery.SendPorts(applicationName, name);
            return retval;
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceSendPortsMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Schema operations

    /// <summary>
    /// Gets all the Schema Information. 
    /// Empty Schema Name returns all Schema.
    /// </summary>
    /// <param name="applicationName">Applications Name</param>
    /// <param name="name">Schema Name</param>
    /// <returns>BizTalkQuery.BTSchema</returns>
    [WebMethod]
    public List<BizTalkQuery.BTSchema> Schemas(string applicationName, string name)
    {
        try
        {
            return bizTalkQuery.Schemas(applicationName, name);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceSchemasMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Gets all the Schema Information by schema type. 
    /// </summary>
    /// <param name="applicationName">Applications Name</param>
    /// <param name="type">Schema Type Name</param>
    /// <returns>BizTalkQuery.BTSchema</returns>
    [WebMethod]
    public List<BizTalkQuery.BTSchema> SchemasByType(string applicationName, string type)
    {
        try
        {
            return bizTalkQuery.SchemasByType(applicationName, type);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceSchemasMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Pipeline operations

    /// <summary>
    /// Gets all the Pipeline Information. 
    /// Empty Pipeline Name returns all Pipeline.
    /// </summary>
    /// <param name="applicationName">Applications Name</param>
    /// <param name="name">Pipeline Name</param>
    /// <returns>BizTalkQuery.BTPipeline</returns>
    [WebMethod]
    public List<BizTalkQuery.BTPipeline> Pipelines(string applicationName, string name)
    {
        try
        {
            return bizTalkQuery.Pipelines(applicationName, name);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServicePipelinesMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    /// <summary>
    /// Gets all the Pipeline Information by pipeline type. 
    /// </summary>
    /// <param name="applicationName">Applications Name</param>
    /// <param name="type">Pipeline Type Name</param>
    /// <returns>BizTalkQuery.BTPipeline</returns>
    [WebMethod]
    public List<BizTalkQuery.BTPipeline> PipelinesByType(string applicationName, string type)
    {
        try
        {
            return bizTalkQuery.PipelinesByType(applicationName, type);
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServicePipelinesMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion

    #region Transform operations

    /// <summary>
    /// Gets all the Transform Information. 
    /// Empty Transform Name returns all Transform.
    /// </summary>
    /// <param name="applicationName">Applications Name</param>
    /// <param name="name">Transform Name</param>
    /// <returns>BizTalkQuery.BTTransform</returns>
    [WebMethod]
    public List<BizTalkQuery.BTTransform> Transforms(string applicationName, string name)
    {
        try
        {
            List<BizTalkQuery.BTTransform> retval = bizTalkQuery.Transforms(applicationName, name);
            return retval;
        }
        catch (Exception ex)
        {
            // log and throw new error
            EventLogger.LogMessage(EventFormatter.FormatEvent(MethodInfo.GetCurrentMethod(), ex),
                                   EventLogEntryType.Error, (int)EventLogger.EventId.BizTalkQueryService);

            throw new SoapException(GetErrorDescription(BizTalkQueryServiceTransformsMessage),
                                    SoapException.ServerFaultCode, ex);
        }
    }

    #endregion
}